<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> 
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html >
	<head>
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
		<meta http-equiv="X-UA-Compatible" content="IE=9" />
		<meta http-equiv="pragma" content="no-cache" />
		<title>获取文章类目</title>
		<%@ include file="../../../common/Admin-list.jsp"%>
		
		<link rel="stylesheet" type="text/css" href="<%=bpath %>Scripts/ztree/zTreeStyle.css" />		
		<script type="text/javascript" src="<%=bpath %>Scripts/ztree/jquery.ztree.all-3.5.js"></script>
	</head>
<body>
<div class="easyui-panel" fit="true" type="panel" border="false">
	<div class="treelist module">
		<div class="hd">
			<h2 class="t">文章类目树</h2>
			<span class="handle4tree" title="显示/隐藏树列表"></span>					
		</div>
		<div class="bd" style="margin-left:20px;">
			<div id="valleyTree" class="ztree"></div>
		</div>
	</div>	
</div>
<script type="text/javascript">
	//加载左侧树
	var setting = {
		async : {
			enable : true,
			url : '../ArticleCategory/getzTreeNodes.json?noAdmin=yes',
			autoParam : [ 'id=parentID', 'level' ],//异步加载时需要自动提交父节点属性的参数			
			dataFilter : zTreefilter
		},	
		callback : {			
			onClick: zTreeOnClick,	
			onAsyncSuccess: onAsyncSuccess
		}
	};
		
	function zTreefilter(treeId, parentNode, childNodes) {
		if (!childNodes)
			return null;
		else {
			for (var i = 0, l = childNodes.length; i < l; i++) {
				if (childNodes[i].isParent=="false") { //不是父类
					childNodes[i].icon="<%=bpath %>Scripts/ztree/img/diy/2.png";				
				}else{					
					childNodes[i].halfCheck = true;					
				}
			}			
			return childNodes;
		}		
	}	
	
	//加载成功后 
	var firstAsyncSuccessFlag = 0;
	function onAsyncSuccess(event, treeId, treeNode, msg) {			
		var zTree = $.fn.zTree.getZTreeObj(treeId);		
		//加载 展开 子节点
		var node=zTree.getNodeByParam("isParent",true,null); //如有多个节点满足查询条件，只返回第一个匹配到的节点 
		zTree.expandNode(node,true,false,true);				
	}
	
	function zTreeOnClick(event, treeId, treeNode) {
		var zTree = $.fn.zTree.getZTreeObj(treeId);
		if(treeNode.levelID=="1"){
			alert("抱歉，一级类目 不允许发布文章！");
			if (treeNode.isParent) {
				zTree.expandNode(treeNode);
			}
		}else{
			//alert(treeNode.name);
			artDialog.opener.document.getElementById('categoryID').value = treeNode.id;
			artDialog.opener.document.getElementById('categoryName').value = treeNode.name;
        	artDialog.close(); // 关闭对话框
		}				
	}	
	
	//页面加载 
	$(function(){		
		
		$.fn.zTree.init($('#valleyTree'), setting);
		
		
	});
	
	
</script>
</body>
</html>